package com.tool_stdy.Reflect;

import java.lang.reflect.Method;

import com.tool_stdy.Model.TeacherBean;

public class MethTest {

	public void say(String name, int age) {
		System.out.println(name + "--->" + age);
	}

	private void hello(){
		System.out.println("hello");
	}
	
	public static void listMethodByclass() {
		Class<TeacherBean> clazz = TeacherBean.class;
		Method[] methods = clazz.getDeclaredMethods();
		for (Method m : methods) {
			System.out.println(m.getName());
		}
	}

	public static void doMethodByNameWithParam() {
		try {
			Class<MethTest> clazz = MethTest.class;
			Method method = clazz.getMethod("say", new Class[] { String.class,int.class });
			Object invoke = method.invoke(clazz.newInstance(), "zs", 10);
			System.out.println(invoke);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void doMethodByNameWithoutParam() throws Exception{
		Class<MethTest> clazz = MethTest.class;
		Method method = clazz.getMethod("hello", null);
		method.setAccessible(true);
		method.invoke(clazz.newInstance(), null);
	}
	
	public static void doprivateMethod() throws Exception{
		Class<MethTest> clazz = MethTest.class;
		Method method = clazz.getDeclaredMethod("hello", null);
		method.setAccessible(true);
		method.invoke(clazz.newInstance(), null);
	}
	
	
	public static void main(String[] args) throws Exception {
		// listMethodByclass();
		//doMethodByNameWithParam();
		//doMethodByNameWithoutParam();
		//doprivateMethod();
		System.out.println("aa".substring(1));
	}
}
